/**
 * @(#)ClientFactory.java 2011
 *
 *
 * Copyright 2011 classic-commerce
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *
 *
 *  This class bootstraps the creation all the application widgets
 *  and "injects" all necessary resources.
 *
 *  @author: <a href="mailto:richard@ioniq.ca">Richard Mutezintare</a>
 *
 */

package ca.ioniq.client.util;

import ca.ioniq.client.ApplicationController;
import ca.ioniq.client.ClassicMessages;
import ca.ioniq.client.presenter.HeaderViewPresenter;
import ca.ioniq.client.presenter.MainContentPresenter;
import ca.ioniq.client.view.ContainerView;
import ca.ioniq.client.view.FooterView;
import ca.ioniq.client.view.HeaderView;
import ca.ioniq.client.view.MainContentView;
import ca.ioniq.client.widget.ErrorMessageWidget;
import ca.ioniq.client.widget.SearchBoxWidget;
import ca.ioniq.client.widget.menu.NavigationMenu;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;

public class ClientFactory {
    private ApplicationController controller;
    private EventBus eventBus;
    private ContainerView containerView;
    private HeaderView headerView;
    private MainContentView mainContentView;
    private FooterView footerView;

    private HeaderViewPresenter headerPresenter;
    private MainContentPresenter mainContentPresenter;

    public ClientFactory() {

        ClassicMessages messages = GWT.create(ClassicMessages.class);

        eventBus = new SimpleEventBus();
        controller = new ApplicationController(eventBus);

        headerView = new HeaderView(new ErrorMessageWidget(messages), messages);
        headerPresenter = new HeaderViewPresenter(headerView, eventBus);

        NavigationMenu menu = new NavigationMenu(new SearchBoxWidget(messages), messages);

        mainContentView = new MainContentView(new ErrorMessageWidget(messages), messages);
        mainContentPresenter = new MainContentPresenter(mainContentView, eventBus);

        containerView = new ContainerView(headerView, menu, mainContentView, new FooterView());
    }

    public ApplicationController getController() { return controller; }
    public EventBus getEventBus() { return eventBus; }
    public ContainerView getContainerView() { return containerView; }
    public HeaderView getHeaderView() { return headerView; }
    public MainContentView getMainContentView() { return mainContentView; }
    public FooterView getFooterView() { return footerView; }
}
